package cn.edu.nchu.fragmentdemo.myComponents.components;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import cn.edu.nchu.fragmentdemo.MainActivity;
import cn.edu.nchu.fragmentdemo.utils.MarkDrawable;
import cn.edu.nchu.fragmentdemo.utils.CommenUtils;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;

import java.io.Serializable;
import java.sql.SQLException;

public class MyArrowMarkerClass extends Marker implements Serializable {
    private MainActivity mainActivity;
    private Context context;
    private MapView mapView;
    private double degree;
    private CommenUtils commenUtils;

    public MyArrowMarkerClass(MapView mapView) {
        super(mapView);
        mainActivity = (MainActivity) MainActivity.getActivity();
        context = mainActivity.getApplicationContext();
        commenUtils = new CommenUtils();
        this.mapView = mapView;
        Bitmap mBitmap = BitmapFactory.decodeResource(context.getResources(), commenUtils.getResource("arrow"));
        MarkDrawable drawable = new MarkDrawable(context.getResources(), mBitmap);
        this.setIcon(drawable);
    }


    public MyArrowMarkerClass(MapView mapView, Context resourceProxy) {
        super(mapView, resourceProxy);
    }

    //新加的：callback
    private DataChangeListener dataChangeListener;// 消息处理完成的监听器

    /**
     * 数据获取完成的监听器
     */
    public interface DataChangeListener {
        void setData(Object result) throws SQLException;
    }

    //
    public void sendMessage(Object message) throws SQLException {
        if (dataChangeListener != null) {
            dataChangeListener.setData(message);// 设置监听器，进行后续操作
        }
    }

    public DataChangeListener getDataChangeListener() {
        return dataChangeListener;
    }

    public void setDataChangeListener(DataChangeListener dataChangeListener) {
        this.dataChangeListener = dataChangeListener;
    }

    public double getDegree() {
        return degree;
    }

    public void setDegree(double degree) {
        this.degree = degree;
    }
}
